﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ListIt.DAL;
using System.Diagnostics;
using System.IO;

namespace Dispatcher.Presenter
{
    public class GenericPresenter : IDisposable
    {
        #region Private Vars
        private ListItDAL _DAL;
        FileStream _ObjStream;
        #endregion


        #region Constructor & Destructor
        public GenericPresenter()
        {
            _ObjStream = new FileStream(@"C:\Logs\DispatchGateway.log", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
            TextWriterTraceListener objTraceListener = new TextWriterTraceListener(_ObjStream);
            Trace.Listeners.Add(objTraceListener);
            _DAL = new ListItDAL();
        }

        public void Dispose()
        {
            Trace.Close();
            _ObjStream.Close();
            _ObjStream.Dispose();
            _DAL.Dispose();
        }
        #endregion

        #region Protected Properties

        #endregion

        #region Public Fn
        public virtual void Present()
        {
            // do nothing
        }

        public void LogEvent(string e)
        {
            Trace.WriteLine(string.Format("[{0}] - {1}", DateTime.Now, e));
            Trace.Flush();
        }

        public ListItDAL DAL
        {
            get
            {
                return _DAL;
            }
        }
        #endregion
    }
}
